< previous page page_543 next page >

Page 543
Next, the routine checks to see if any face is further from the center of projection than the first face in the Faces collection. If so, that face is moved to the front of the list. The routine repeats this process until no face is further than the face at the front.
At that point, SortFaces moves the first face to the sorted output collection, and it starts all over again. When all the faces have been moved to the output collection, SortFaces sets the Faces collection to point to the rearranged objects, and the routine is finished.
There are two major complications to this method. First, it may not be possible to find a face that is further than any other from the center of projection. Figure 15.9 shows two overlapping surfaces. Because they overlap each other, neither one is further from the center of projection. The simplest way to take care of this situation is to break the mutually overlapping surfaces into smaller pieces that do not overlap in this way. Then this problem does not arise.
To be certain it does not become stuck in an infinite loop if this situation does occur, SortFaces keeps track of the number of times it has moved a face to the front of the list. If there are N items remaining to be ordered and the routine has moved N items to the front of the list, the subroutine is stuck in an infinite loop. In that case, the routine breaks out of the loop by moving the first item on the list to the output collection. While this does not guarantee a proper ordering of the faces, it allows the program to continue and produce some sort of output.
Comparing Faces
The second complication to the ordering process is that it is not always easy to determine whether one of a solid's faces obscures another. The SortFaces routine performs a series of tests to determine if two faces overlap. First, it checks the maximum and minimum X and Y coordinates of the two faces. If the X and Y coordinate ranges of the two faces do not overlap, the faces themselves cannot overlap. In this case, one face lies to the side of the other, so neither can block the view of the other from the center of projection.
The routine also checks whether the largest Z coordinate of the first face is smaller than the smallest Z coordinate of the second. If it is, the first face must be further from the center of projection than the second face so that the program does not need to move the second face to the front of the list.
z0563-01.gif
Figure 15.9
Mutually overlapping faces.

 
< previous page page_543 next page >